import QtQuick 2.13
import QtQuick.Window 2.13
import QtQuick.Controls 2.13
import QtQuick.Controls.Styles 1.2
import LoginControl 1.0
ApplicationWindow
{
    id :loginWin
    visible: true
    x:Screen.desktopAvailableWidth/2-width/2
    y: Screen.desktopAvailableHeight/2-height/2
    width: 280
    height: 360
    color: "#00ffffff"
    title: "Login"
    maximumHeight: 480
    maximumWidth: 320
    flags: Qt.Window | Qt.FramelessWindowHint //去标题栏
    property bool isloading:false
    signal callLogin(string user,string password);
    LoginControl{
        id : loginApi
    }


    function test(data){
        console.log("dafaadt",data)
    }

    function uiDologin(user,password){
         loginApi.doLogin(user,password)
    }
    Rectangle{
        id: removeWindows
        x:32
        height: 32
        width: parent.width-x*2
        color: "#00ffffff"
        Image {
            x:parent.width
            width: 32
            height: 32
            source: "qrc:/other/icon/addto.png"
        }
        MouseArea { //为窗口添加鼠标事件
            acceptedButtons: Qt.LeftButton //只处理鼠标左键
            property point clickPos: "0,0"
            anchors.fill: removeWindows
            onPressed: { //接收鼠标按下事件
                clickPos  = Qt.point(mouse.x,mouse.y)
            }
            onPositionChanged: { //鼠标按下后改变位置
                //鼠标偏移量
                var delta = Qt.point(mouse.x-clickPos.x, mouse.y-clickPos.y)
                //如果mainwindow继承自QWidget,用setPos
                loginWin.setX(loginWin.x+delta.x)
                loginWin.setY(loginWin.y+delta.y)
            }
        }

    }
    Rectangle{
        y:80
        x:parent.width/2-32
        width: 64
        height: 64
        color: "#00000000"
        Image {
            width: 64
            height: 64
            source: "qrc:/other/icon/xiaoma.png"
        }
    }

    Rectangle {
        id:buttonExit
        width: 32
        height: 32
        color: "#00ff0000"
        visible: true
        Image {
            width: 32
            height: 32
            source: "qrc:/other/icon/close.png"
        }
        MouseArea{
            anchors.fill: buttonExit
            onClicked: Qt.quit()
        }
    }
    Rectangle{
        y:200
        width: parent.width
        height: 120
        color: "#00ffffff"

        StackView{
            id:loginStack
            initialItem: "LoginBeforePage.qml"
            anchors.fill: parent
        }

    }


    Connections{
        target: loginApi
        onLoginSuccess:{
            console.log("login success")
            loginWin.isloading=true
//            console.log(isloading)
//            console.log(loginWin.isloading)
            loginApi.showMain()

        }
    }
    Connections{
        target: loginApi
        onLoginError:{
            console.log("login error")
        }
    }
    Connections{
        target: loginApi
        onLoginDoing:{
            console.log("login doing")
            loginStack.push("LoginLoading.qml")
        }
    }

}
